/**
 * Definition for a binary tree node.
 * function TreeNode(val) {
 *     this.val = val;
 *     this.left = this.right = null;
 * }
 */
/**
 * @param {number[]} nums
 * @return {TreeNode}
 */
var sortedArrayToBST = function(nums) {
    return fun(nums, 0, nums.length)
};
// >=s, <e
function fun(nums, s, e){
    if(s === e)return null;
    let mid = Math.floor((s+e)/2);
    let node = new TreeNode(nums[mid]);
    node.left = fun(nums, s, mid);
    node.right = fun(nums, mid+1, e);

    return node;
}